package org.vectrics.recruiter.struts.admin.job;

import javax.servlet.jsp.JspException;

import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.JobFunction;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;

/**
 * @author pgoette Clase encargada de Recuperar los datos del Function para
 *         editarlos.
 */
public class EditJobFunctionAction extends VectricsStrutsAction {

	@Override
	protected String doExecute(VectricsActionData actionData)
			throws JspException {

		String forward = "success";
		String code = actionData.getRequest().getParameter("functionCode");
		JobFunctionForm form = (JobFunctionForm) actionData.getForm();

		// Si code es distinto de nulo recupero la Function y la cargo en el
		// Form
		if (code != null) {
			JobFunction function = RecruitServiceLocator.getJobProvider()
					.findFunction(code);
			form.setCode(function.getCode());
			form.setDescription(function.getDescription());
			// TODO
			// Agregado por mi
			form.setWeight(function.getWeight());

			form.setJobFunctionType(function.getJobFunctionType());
			
			form.setJobFunctionTypeId(function.getJobFunctionType().getId());

			form.setJobFunctionTypes(RecruitServiceLocator.getJobProvider()
					.findAllJobFunctionsType());
			
			form.setProfileLink(function.getProfileLink());

		} else {
			forward = "invalid";
		}

		return forward;
	}

}
